package com.ruoyi.dataserver.service.impl;

import com.ruoyi.dataserver.api.dto.LengthResultDTO;
import com.ruoyi.dataserver.api.dto.ScopeDto;
import com.ruoyi.dataserver.api.dto.StatisticDto;
import com.ruoyi.dataserver.api.dto.StatisticResultDTO;
import com.ruoyi.dataserver.api.entity.DataDetail;
import com.ruoyi.dataserver.constant.StatisticConstants;
import com.ruoyi.dataserver.dto.LayerDto;
import com.ruoyi.dataserver.remote.RemoteService;
import com.ruoyi.dataserver.service.ISearchTableService;
import com.ruoyi.dataserver.service.IStatisticsService;
import com.ruoyi.dataserver.utils.R;
import com.ruoyi.dataserver.api.entity.StatisticsData;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ProjectName intelligent-city
 * @Package com.lab.dataserver.service.impl
 * @ClassName StatisticsServiceImpl
 * @Description 统计服务实现类
 * @Company LABmaterialStatistics
 * @Author LXK
 * @Date 2020/6/24 8:58
 * @UpdateUser
 * @UpdateDate
 * @UpdateRemark
 * @Version 1.0.0
 */
@Slf4j
@Component
public class StatisticsServiceImpl implements IStatisticsService {

  /**
   * remoteService:
   */
  @Autowired
  public RemoteService remoteService;

  @Autowired
  public JdbcTemplate jdbcTemplate;

  @Autowired
  public ISearchTableService tableService;

  @Override
  public Long queryForObject() {
    return jdbcTemplate.queryForObject("select count(*) from smdtv_35 ", Long.class);
  }

  @Override
  public LengthResultDTO queryLengthResultBySql(String tablename, ScopeDto scopeDto) {
    String sql = "select sum(t.CD) as length from \"" + tablename+"\"" +" t where 1=1 ";
    String scopeSqlTotal = "";
    if (scopeDto != null) {
      scopeSqlTotal = lineScopeSql("and", scopeDto);//拼接查询条件
    }
    sql = sql + scopeSqlTotal;
    List<LengthResultDTO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(LengthResultDTO.class));
    if(null == list.get(0).getLength()){
      return new LengthResultDTO();
    }
    return list.get(0);
  }


  public List<StatisticsData> queryStatisticResultBySql(String sql) {
    List<StatisticsData> list = null;
    if (StringUtils.isNotBlank(sql)) {
      list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(StatisticsData.class));
    }
    return list;
  }

  public List<DataDetail> queryDataDetailBySql(String sql) {
    List<DataDetail> list = null;
    if (StringUtils.isNotBlank(sql)) {
      list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DataDetail.class));
    }
    return list;
  }


  @Override
  public StatisticResultDTO pipeLines(StatisticDto statisticDto) {
    return lineStatistics(statisticDto);
  }

  @Override
  public StatisticResultDTO pipeDiameter(StatisticDto statisticDto) {
    statisticDto.setGroupBy(StatisticConstants.Statistic_Type_GJ);
    return lineStatistics(statisticDto);
  }

  @Override
  public StatisticResultDTO manholeCountStatistics(StatisticDto statisticDto) {
    StatisticResultDTO statisticResultDTO = pointStatistics(statisticDto,
        StatisticConstants.SQLPreConnector_LIKE);
    return statisticResultDTO;
  }

  @Override
  public StatisticResultDTO valveCountStatistics(StatisticDto statisticDto) {
    StatisticResultDTO statisticResultDTO = pointStatistics(statisticDto,
        StatisticConstants.SQLPreConnector_Eq);
    return statisticResultDTO;
  }

  @Override
  public StatisticResultDTO materialStatistics(StatisticDto statisticDto) {
    StatisticResultDTO statisticResultDTO = linecStatistics(statisticDto, null);
    return statisticResultDTO;
  }

  @Override
  public StatisticResultDTO accessoriesStatistics(StatisticDto statisticDto) {
    StatisticResultDTO statisticResultDTO = pointStatistics(statisticDto, StatisticConstants.SQLPreConnector_Trim);
    return statisticResultDTO;
  }

  /**
   * @param statisticDto :
   * @return com.lab.dataserver.api.dto.StatisticResultDTO
   * @Title lineStatistics
   * @Description 管线通用统计
   * @author wangzhx
   * @date 2022/2/19 15:03
   * @UpdateUser
   * @UpdateDate
   * @UpdateRemark
   */

  private StatisticResultDTO lineStatistics(StatisticDto statisticDto) {
    StatisticResultDTO statisticResultDTO = new StatisticResultDTO();
    String[] layerList = statisticDto.getLayerList();
    String[] layerNameStrs = obtainLayerNameStrs(statisticDto.getLayerList());
    String groupBy = statisticDto.getGroupBy();
    String sqlWhere = "";
    if (statisticDto.getQueryCondition() != null) {
      sqlWhere = obtainQueryCondition(statisticDto.getQueryCondition(),
          StatisticConstants.SQLPreConnector_IN);
    }
    List<StatisticsData> statisticsDataList = new ArrayList<StatisticsData>();
    Long totalCount = 0L;
    Double totalLength = Double.valueOf(0);
    for (int i = 0; i < layerNameStrs.length; i++) {
      String layer = layerList[i];
      // 查询图层名称
      String layerLabel = matchingLabelOfLayerName(layer);
      //String layerLabel = getLayerNameList(layerList[i]);
      String layerTable = layerNameStrs[i];
      String SQLPreConnector = "";
      if (StringUtils.isNotBlank(sqlWhere)) {
        SQLPreConnector = StatisticConstants.SQLPreConnector_AND;
      }
      String scopeSql = lineScopeSql(SQLPreConnector, statisticDto.getScope());
      StatisticsData dto = lengthStatistic(layer, layerTable, sqlWhere, scopeSql, groupBy);
      if (dto != null) {
        if (dto.getCount() != 0) {
          totalCount += dto.getCount();
        }
        if (dto.getLength() != null) {
          totalLength += dto.getLength();
        }
        dto.setLayerName(layerLabel);
        statisticsDataList.add(dto);
      }
    }
    statisticResultDTO.setTotalCount(totalCount);
    statisticResultDTO.setTotalLength(totalLength);
    statisticResultDTO.setStatisticsData(statisticsDataList);
    return statisticResultDTO;
  }

  /**
   * @param statisticDto :
   * @param sqlWhereConnector :
   * @return com.lab.dataserver.api.dto.StatisticResultDTO
   * @Title pointStatistics
   * @Description 管点数量统计
   * @author heff
   * @date 2020/7/15 8:08
   * @UpdateUser
   * @UpdateDate
   * @UpdateRemark
   */

  private StatisticResultDTO pointStatistics(StatisticDto statisticDto, String sqlWhereConnector) {
    StatisticResultDTO statisticResultDTO = new StatisticResultDTO();
    String[] layerList = statisticDto.getLayerList();
    String[] layerNameStrs = obtainLayerNameStrs(statisticDto.getLayerList());//获取图层名称，多个用逗号分隔 DM，图层名称（多个用逗号分隔），从statisticDto的layerList拆解获取
    String groupBy = statisticDto.getGroupBy();
    String sqlWhere = "";
    Map<String, String[]> queryCondition = statisticDto.getQueryCondition();
    if (queryCondition != null && !queryCondition.isEmpty()) {
      sqlWhere = obtainQueryCondition(statisticDto.getQueryCondition(), sqlWhereConnector);
    }
    String scopeSqlTotal = "";
    if (statisticDto.getScope() != null) {
      scopeSqlTotal = pointScopeSql(null, statisticDto.getScope());//拼接查询条件
    }
    List<StatisticsData> statisticsDataList = new ArrayList<StatisticsData>();
    Long totalCount = 0L;
    Double totalLength = Double.valueOf(0);
    String scopeSql = "";//查询范围
    if (statisticDto.getScope() != null && StringUtils.isNotBlank(sqlWhere) && StringUtils.isNotBlank(scopeSqlTotal)) {
      scopeSql = StatisticConstants.SQLPreConnector_AND + scopeSqlTotal;
    }else{
      scopeSql = scopeSqlTotal;
    }
    for (int i = 0; i < layerNameStrs.length; i++) {
      String cols = "\'" + layerList[i] + "\' as layer,\'合计\' as fieldName,count(*) as count";
      if(layerNameStrs[i].toLowerCase().contains("line")){
        cols += ",sum(t.CD) as length";
      }
      String tableWhereConnector = "";
      if(StringUtils.isNotBlank(sqlWhere)){
        tableWhereConnector = " where ";
      }
      String table = "(select * from \"" + layerNameStrs[i]+"\"" + tableWhereConnector + sqlWhere +") t";
      String layerLabel = matchingLabelOfLayerName(layerList[i]);

      //String layerLabel = getLayerNameList(layerList[i]);

      String sql = makeSql(cols, table, scopeSqlTotal, null, null);
      List<StatisticsData> list = queryStatisticResultBySql(sql);
      StatisticsData dto = new StatisticsData();
      if (list != null && !list.isEmpty()) {
        dto = list.get(0);
        if (dto != null) {
          if (dto.getCount() != 0) {
            totalCount += dto.getCount();
          }
          String detailColsSql = "count(*) as count," + groupBy + " as fieldName";
          if(layerNameStrs[i].toLowerCase().contains("line")){
            if (dto.getLength() != null) {
              totalLength += dto.getLength();
            }
            detailColsSql += ",sum(t.CD) as length";
          }
          String detailListSql = makeSql(detailColsSql, "\""+layerNameStrs[i] + "\" t ",
              "("+sqlWhere+")" + scopeSql,
              groupBy, null);
          List<DataDetail> dataDetails = queryDataDetailBySql(detailListSql);
          if (dataDetails != null && !dataDetails.isEmpty()) {
            dto.setDetailList(dataDetails);
          }
          dto.setLayerName(layerLabel);
          statisticsDataList.add(dto);
        }
      }
    }
    statisticResultDTO.setTotalCount(totalCount);
    statisticResultDTO.setTotalLength(totalLength);
    statisticResultDTO.setStatisticsData(statisticsDataList);
    return statisticResultDTO;
  }
  /**
   * @param statisticDto :
   * @param sqlWhereConnector :
   * @return com.lab.dataserver.api.dto.StatisticResultDTO
   * @Title pointStatistics
   * @Description 材质分类统计
   * @author heff
   * @date 2020/7/15 8:08
   * @UpdateUser
   * @UpdateDate
   * @UpdateRemark
   */

  private StatisticResultDTO linecStatistics(StatisticDto statisticDto, String sqlWhereConnector) {
    StatisticResultDTO statisticResultDTO = new StatisticResultDTO();
    String[] layerList = statisticDto.getLayerList();
    String[] layerNameStrs = obtainLayerNameStrs(statisticDto.getLayerList());//获取图层名称，多个用逗号分隔 DM，图层名称（多个用逗号分隔），从statisticDto的layerList拆解获取
    String groupBy = statisticDto.getGroupBy();
    String sqlWhere = " 1=1 ";
    Map<String, String[]> queryCondition = statisticDto.getQueryCondition();
    if (queryCondition != null && !queryCondition.isEmpty()) {
      sqlWhere = obtainQueryCondition(statisticDto.getQueryCondition(), sqlWhereConnector);
    }
    String scopeSqlTotal = "";
    if (statisticDto.getScope() != null) {
      scopeSqlTotal = lineScopeSql(null, statisticDto.getScope());//拼接查询条件
    }
    List<StatisticsData> statisticsDataList = new ArrayList<StatisticsData>();
    Long totalCount = 0L;
    Double totalLength = Double.valueOf(0);
    String scopeSql = "";//查询范围
    if (statisticDto.getScope() != null && StringUtils.isNotBlank(sqlWhere) && StringUtils.isNotBlank(scopeSqlTotal)) {
      scopeSql = StatisticConstants.SQLPreConnector_AND + scopeSqlTotal;
    }else{
      scopeSql = scopeSqlTotal;
    }
    for (int i = 0; i < layerNameStrs.length; i++) {
      String cols = "\'" + layerList[i] + "\' as layer,\'合计\' as fieldName,count(*) as count";
     // if(layerNameStrs[i].toLowerCase().contains("line")){
        cols += ",sum(t.CD) as length";
      //}
      String tableWhereConnector = "";
      if(StringUtils.isNotBlank(sqlWhere)){
        tableWhereConnector = " where ";
      }
      String table = "(select * from \"" + layerNameStrs[i]+"\"" + tableWhereConnector + sqlWhere +") t";



      //
       String layerLabel = matchingLabelOfLayerName(layerList[i]);

      //String layerLabel = getLayerNameList(layerList[i]);
      String sql = makeSql(cols, table, scopeSqlTotal, null, null);
      List<StatisticsData> list = queryStatisticResultBySql(sql);
      StatisticsData dto = new StatisticsData();
      if (list != null && !list.isEmpty()) {
        dto = list.get(0);
        if (dto != null) {
          if (dto.getCount() != 0) {
            totalCount += dto.getCount();
          }
          String detailColsSql = "count(*) as count," + groupBy + " as fieldName";
          //if(layerNameStrs[i].toLowerCase().contains("line")){
            if (dto.getLength() != null) {
              totalLength += dto.getLength();
            }
            detailColsSql += ",sum(t.CD) as length";
         // }
          String detailListSql = makeSql(detailColsSql, "\""+layerNameStrs[i] + "\" t ",
                  "("+sqlWhere+")" + scopeSql,
                  groupBy, null);
          List<DataDetail> dataDetails = queryDataDetailBySql(detailListSql);
          if (dataDetails != null && !dataDetails.isEmpty()) {
            dto.setDetailList(dataDetails);
          }
          dto.setLayerName(layerLabel);
          statisticsDataList.add(dto);
        }
      }
    }
    statisticResultDTO.setTotalCount(totalCount);
    statisticResultDTO.setTotalLength(totalLength);
    statisticResultDTO.setStatisticsData(statisticsDataList);
    return statisticResultDTO;
  }
  /**
   * @param layerTable :
   * @param sqlWhere :
   * @param scopeSql :
   * @param groupBy :
   * @return void
   * @Title lengthStatistics
   * @Description 长度统计
   * @author heff
   * @date 2020/7/12 19:40
   */

  private StatisticsData lengthStatistic(String layer, String layerTable, String sqlWhere,
      String scopeSql, String groupBy) {
    StatisticsData dto = new StatisticsData();
    String colsSql =
        "\'" + layer + "\' as layer,\'合计\' as fieldName,sum(t.CD) as length,count(*) as count";
    String tableSql = "\""+layerTable + "\" t ";
    String conditionSql = sqlWhere + scopeSql;
    String layerSql = makeSql(colsSql, tableSql, conditionSql, null, "length");
    List<StatisticsData> list = queryStatisticResultBySql(layerSql);
    if (list != null && !list.isEmpty()) {
      dto = list.get(0);
      String detailColsSql = "sum(t.CD) as length,count(*) as count," + groupBy + " as fieldName";
      String detailListSql = makeSql(detailColsSql, tableSql, conditionSql, groupBy, null);
      List<DataDetail> dataDetails = queryDataDetailBySql(detailListSql);
      if (dataDetails != null && !dataDetails.isEmpty()) {
        dto.setDetailList(dataDetails);
      }
    }
    return dto;
  }

  /**
   * @param cols :
   * @param table :
   * @param condition :
   * @param groupBy :
   * @param order :
   * @return java.lang.String
   * @Title makeSql
   * @Description 构造sql脚本
   * @author heff
   * @date 2020/7/14 11:43
   * @UpdateUser
   * @UpdateDate
   * @UpdateRemark
   */

  private String makeSql(String cols, String table, String condition, String groupBy,
      String order) {
    StringBuilder sql = new StringBuilder();
    sql.append("select ").append(cols).append(" from ").append(table);
    if(StringUtils.isNotBlank(condition)  &&  !"()".equals(condition)   ){//mag 20220217 bug修改
      sql.append(" where ").append(condition);
    }
    if (StringUtils.isNotBlank(groupBy)) {
      sql.append(" group by ").append(groupBy);
    }
    if (StringUtils.isNotBlank(order)) {
      sql.append(" order by ").append(order);
    }
    return sql.toString();
  }

  /**
   * @param layers :
   * @return java.lang.String[]
   * @Title obtainLayerNameStrs
   * @Description 获取图层名称，多个用逗号分隔 DM，图层名称（多个用逗号分隔），从statisticDto的layerList拆解获取
   * @author heff
   * @date 2020/7/10 15:35
   * @UpdateUser
   * @UpdateDate
   * @UpdateRemark
   */

  private String[] obtainLayerNameStrs(String[] layers) {
    String layerNames = "";
    if (layers != null) {
      for (int i = 0; i < layers.length; i++) {
        String layerInfo = layers[i];
        String layerType = layerInfo.split("@")[0];
        String layerName = "";
        if(layerType.indexOf("LINE") == -1){
          layerName = tableService.searchPointTable(layerInfo.split("_")[0]);  // 组成管线表名
        }else{
          layerName = tableService.searchLineTable(layerInfo.split("_")[0]);  // 组成管线表名
        }
        if (i == 0) {
          layerNames = layerName;
        } else {
          layerNames = layerNames + "," + layerName;
        }
      }
    }

    log.info("当前查询参数，图层名称是：{}", layerNames);
    String[] layerNameStrs = layerNames.split(",");
    return layerNameStrs;
  }

  /**
   * @param queryConditionMap :
   * @return java.lang.String
   * @Title obtainQueryCondition
   * @Description 拼接查询条件
   * @author heff
   * @date 2020/7/13 10:46
   * @UpdateUser
   * @UpdateDate
   * @UpdateRemark
   */

  private String obtainQueryCondition(Map<String, String[]> queryConditionMap, String connector) {
    StringBuilder sqlWhere = new StringBuilder();
    if (!queryConditionMap.isEmpty() && !queryConditionMap.entrySet().isEmpty()) {
      for (Map.Entry<String, String[]> entry : queryConditionMap.entrySet()) {
        String[] strings = entry.getValue();
        String[] cleanStrings = dealWithNull(strings);
        if (strings.length != 0) {
          // 多个查询条件拼接用 AND
          if (sqlWhere.length() > 0) {
            sqlWhere.append(" AND ");
          }
          String sql = "";
          switch (connector) {
            case "LIKE":
              for (String str : cleanStrings) {
                if (StringUtils.isNotBlank(sql)) {
                  sql += " or ";
                }
                sql += entry.getKey() + " like " + "\'%" + str + "%\'";
              }
              break;
            case "IN":
              sql = entry.getKey() + " in " + "(\'" + String.join("\',\'", cleanStrings) + "\')";
              break;
            case "Eq":
              for (String str : cleanStrings) {
                if (StringUtils.isNotBlank(sql)) {
                  sql += " or ";
                }
                sql += entry.getKey() + " = " + "\'" + str + "\'";
              }
              break;
            case "Trim":
              sql = " trim("+ entry.getKey()+") is not null ";
              break;
            default:
              sql = "";
          }
          sqlWhere.append(sql);
        }
      }
      return sqlWhere.toString();
    }
    return "";
  }

  /**
   * @param strings :
   * @return java.lang.String[]
   * @Title dealWithNull
   * @Description 处理数组中的null和""值
   * @author heff
   * @date 2020/7/13 17:12
   * @UpdateUser
   * @UpdateDate
   * @UpdateRemark
   */
  private String[] dealWithNull(String[] strings) {
    String[] strs = null;
    if (strings != null) {
      List<String> list = new ArrayList<>();
      for (int i = 0; i < strings.length; i++) {
        list.add(strings[i]);
      }
      if (list != null && !list.isEmpty()) {
        while (list.remove(null)) {
        }
        while (list.remove("")) {
        }
      }
      strs = list.toArray(new String[list.size()]);
    }
    return strs;
  }

  /**
   * @param scopeDto :
   * @return java.lang.String
   * @Title scopeSql
   * @Description 如果上传范围参数，拼接对应的sql
   * @author heff
   * @date 2020/7/9 11:11
   * @UpdateUser
   * @UpdateDate
   * @UpdateRemark
   */

  private String scopeSql(String SQLPreConnector, ScopeDto scopeDto) {
    Double xmin = null;
    Double ymin = null;
    Double xmax = null;
    Double ymax = null;
    if (scopeDto != null) {
      xmin = scopeDto.getXmin();
      ymin = scopeDto.getYmin();
      xmax = scopeDto.getXmax();
      ymax = scopeDto.getYmax();
    }
    StringBuilder stringBuilder = new StringBuilder();
    if (xmin != null) {
      stringBuilder.append(" t.shape.MINX >= " + xmin);
    }
    if (ymin != null) {
      stringBuilder.append(" AND t.shape.MINY >= " + ymin);
    }
    if (xmax != null) {
      stringBuilder.append(" AND t.shape.MAXX < " + xmax);
    }
    if (ymax != null) {
      stringBuilder.append(" AND t.shape.MAXY < " + ymax);
    }
    if (StringUtils.isNotBlank(SQLPreConnector) && StringUtils.isNotBlank(stringBuilder)) {
      stringBuilder.insert(0, SQLPreConnector);
    }
    return stringBuilder.toString();
  }
  /**
   * @param scopeDto :
   * @return java.lang.String
   * @Title lineScopeSql
   * @Description 如果上传范围参数，管线拼接对应的sql
   * @author wangzhx
   * @date 2022/2/19 11:11
   * @UpdateUser
   * @UpdateDate
   * @UpdateRemark
   */

  private String lineScopeSql(String SQLPreConnector, ScopeDto scopeDto) {
    Double xmin = null;
    Double ymin = null;
    Double xmax = null;
    Double ymax = null;
    if (scopeDto != null) {
      xmin = scopeDto.getXmin();
      ymin = scopeDto.getYmin();
      xmax = scopeDto.getXmax();
      ymax = scopeDto.getYmax();
    }
    StringBuilder stringBuilder = new StringBuilder();
    if (xmin != null) {
      stringBuilder.append(" LEAST(t.s_x,t.e_x) >= " + xmin);
    }
    if (ymin != null) {
      stringBuilder.append(" AND LEAST(t.s_y,t.e_y) >= " + ymin);
    }
    if (xmax != null) {
      stringBuilder.append(" AND GREATEST(t.s_x,t.e_x) < " + xmax);
    }
    if (ymax != null) {
      stringBuilder.append(" AND GREATEST(t.s_y,t.e_y) < " + ymax);
    }
    if (StringUtils.isNotBlank(SQLPreConnector) && StringUtils.isNotBlank(stringBuilder)) {
      stringBuilder.insert(0, SQLPreConnector);
    }
    return stringBuilder.toString();
  }

  /**
   * @param scopeDto :
   * @return java.lang.String
   * @Title pointScopeSql
   * @Description 如果上传范围参数，管点拼接对应的sql
   * @author wangzhx
   * @date 2022/2/19 11:11
   * @UpdateUser
   * @UpdateDate
   * @UpdateRemark
   */

  private String pointScopeSql(String SQLPreConnector, ScopeDto scopeDto) {
    Double xmin = null;
    Double ymin = null;
    Double xmax = null;
    Double ymax = null;
    if (scopeDto != null) {
      xmin = scopeDto.getXmin();
      ymin = scopeDto.getYmin();
      xmax = scopeDto.getXmax();
      ymax = scopeDto.getYmax();
    }
    StringBuilder stringBuilder = new StringBuilder();
    if (xmin != null) {
      stringBuilder.append(" t.n_x >= " + xmin);
    }
    if (ymin != null) {
      stringBuilder.append(" and t.n_y >= " + ymin);
    }
    if (xmax != null) {
      stringBuilder.append(" and t.n_x < " + xmax);
    }
    if (ymax != null) {
      stringBuilder.append(" and t.n_y < " + ymax);
    }
    if (StringUtils.isNotBlank(SQLPreConnector) && StringUtils.isNotBlank(stringBuilder)) {
      stringBuilder.insert(0, SQLPreConnector);
    }
    return stringBuilder.toString();
  }
  /**
   * @param name :
   * @return java.lang.String
   * @Title matchingLabelOfLayerName
   * @Description 获取图层名称 name-WSG_LINE@hthx1984；label-污水管线
   * @author heff
   * @date 2020/7/13 14:17
   * @UpdateUser
   * @UpdateDate
   * @UpdateRemark
   */

  public String matchingLabelOfLayerName(String name) {
    String label = "";
    String sql = "select value from layername where name = '"+name+"'";
    RowMapper<LayerDto> tableRowMapper = new BeanPropertyRowMapper<LayerDto>(LayerDto.class);
    List<LayerDto> tableList = jdbcTemplate.query(sql, tableRowMapper);
    if(tableList.size() > 0){
      label = tableList.get(0).getValue();
    }
    return label;
  }


  private String getLayerNameList(String layer) {

    Map<String,Object>  map=new HashMap<>();
    map.put("JSG_POINT","给水管点");
    map.put("JSG_LINE","给水管线");
    map.put("JSG_LINE_TEXT","给水管线注记");
    map.put("JSG_BOUNDLINE","给水井室边框");
    map.put("SSG_POINT","输水管点");
    map.put("SSG_LINE","输水管线");

    map.put("SSG_LINE_TEXT","输水管线注记");
    map.put("SSG_BOUNDLINE","输水井室边框");
    map.put("XSG_POINT","消防水管点");
    map.put(" XSG_LINE","消防水管线");
    map.put("XSG_LINE_TEXT","消防水管线注记");
    map.put("JSG_BOUNDLINE","消防水井室边框");
    System.out.println("++++++++++++++++++++++++++++++++++"+map.get(layer));
    return (String) map.get(layer);
  }



}
